package com.sxc.OnlineStore.goods.dao;

import com.sxc.OnlineStore.Utils.ConnectMySql;
import com.sxc.OnlineStore.goods.domain.Goods;

import java.sql.*;
import java.util.ArrayList;

public class GoodsImp {
    private Connection conn = ConnectMySql.conMysql();//定义好数据库对象
    private CallableStatement cs = null; //初始化调用存储过程
    private ResultSet rs = null; //定义rs
    private PreparedStatement ps = null;
    private String sql = null;

<<<<<<< HEAD
    //查询商品PW

=======
    //查询商品PK
    public int GetGoodPK(int goodsID){
        Goods goods = new Goods();
        try {
            sql = "";//代办

            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while (rs.next()){
                goods.setGoods_id(rs.getInt(1));//获得goods的PK
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return goods.getGoods_id();
    }
>>>>>>> 还没有实现在servlet中获取sessiond


    //商品列表
    public ArrayList<Goods> QueryGoods(){
        try {
            ArrayList<Goods> goodsArrayList = new ArrayList<>();

            sql = "SELECT * FROM goods ";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while (rs.next()){
                Goods goods = new Goods();

                goods.setGoods_id(rs.getInt(1));
                goods.setGoods_name(rs.getString(2));
                goods.setGoods_details(rs.getString(3));
                goods.setGoods_price(rs.getString(4));
                goods.setGoods_stock(rs.getString(5));
                goods.setGoods_picture(rs.getString(6));

                goodsArrayList.add(goods);//添加goodsArrayList集合添加goods的每个元素
            }

            System.out.println(goodsArrayList);
            return goodsArrayList;
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return null;
    }


}
